package lc.Q200_250;

import java.util.ArrayDeque;
import java.util.Deque;

public class Q232 {
    static class MyQueue {

        // 使用双栈
        private Deque<Integer> inStack = new ArrayDeque<Integer>();
        private Deque<Integer> outStack = new ArrayDeque<>();

        public MyQueue() {

        }

        public void push(int x) {
            inStack.push(x);
        }

        public int pop() {
            if (outStack.isEmpty()) {
                inToOut();
            }
            return outStack.pop();
        }

        public int peek() {
            if (outStack.isEmpty()) {
                inToOut();
            }
            return outStack.peek();
        }

        public boolean empty() {
            return inStack.isEmpty() && outStack.isEmpty();
        }

        private void inToOut() {
            while (!inStack.isEmpty()) {
                outStack.push(inStack.pop());
            }
        }
    }

}
